package com.gma.userprofile.info.natural

import com.gma.userprofile.util.{HBaseUtil, SparkUtil}
import org.apache.spark.sql.{DataFrame, SparkSession}

object UserProfileSex {
  def main(args: Array[String]): Unit = {

    //获取分区参数
    val ds = args.head

    //1、创建spark sql环境
    val spark: SparkSession = SparkUtil.getSparkSession

    //导入隐式转换
    import spark.implicits._
    import org.apache.spark.sql.functions._

    //2、从hive中获取表
    val userinfo: DataFrame = spark
      .table("dim.dim_pub_user_info_d_f") //获取用户维度表
      .where($"ds" === ds) //获取对应分区数据

    //3、提取性别标签
    val sexTag: DataFrame = userinfo
      .select($"id", when($"sex" === "1", "男").when($"sex" === "2", "女").otherwise("其它") as "sex")

    //4、将数据保存到hbase
    HBaseUtil.tagToHBase(sexTag, "sex")
  }
}
